package com.core.reach.cloudhub.controller;

import com.core.reach.cloudhub.domain.CommonResult;
import com.core.reach.cloudhub.service.StorageService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author ga.zhang
 * @version V1.0
 * @description: TODO
 * @date 2020/4/1 15:56
 **/
@RestController
public class StorageController {

    @Resource
    private StorageService storageService;

    @PostMapping("storage/decrease")
    public CommonResult decrease(@RequestParam("productId") Long productId,
                                 @RequestParam("count") Integer count) {
        Boolean reduceStorage = storageService.reduceStorage(productId, count);
        if (reduceStorage) {
            return new CommonResult(200, "扣减库存成功", Boolean.TRUE);
        } else {
            return new CommonResult(444, "扣减库存失败", Boolean.FALSE);
        }
    }

}
